
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _utils = require('../utils');

const _popup = require('../mixins/popup');

const _icon = _interopRequireDefault(require('../icon'));

const _createNamespace = (0, _utils.createNamespace)('popup');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

const _default = createComponent({
  mixins: [(0, _popup.PopupMixin)()],
  props: {
    round: Boolean,
    duration: [Number, String],
    closeable: Boolean,
    transition: String,
    safeAreaInsetBottom: Boolean,
    closeIcon: {
      type: String,
      default: 'cross',
    },
    closeIconPosition: {
      type: String,
      default: 'top-right',
    },
    position: {
      type: String,
      default: 'center',
    },
    overlay: {
      type: Boolean,
      default: true,
    },
    closeOnClickOverlay: {
      type: Boolean,
      default: true,
    },
  },
  beforeCreate: function beforeCreate() {
    const _this = this;

    const createEmitter = function createEmitter(eventName) {
      return function (event) {
        return _this.$emit(eventName, event);
      };
    };

    this.onClick = createEmitter('click');
    this.onOpened = createEmitter('opened');
    this.onClosed = createEmitter('closed');
  },
  render: function render() {
    let _bem;

    const h = arguments[0];

    if (!this.shouldRender) {
      return;
    }

    const { round } = this;
    const { position } = this;
    const { duration } = this;
    const isCenter = position === 'center';
    const transitionName = this.transition || (isCenter ? 'van-fade' : `van-popup-slide-${position}`);
    const style = {};

    if ((0, _utils.isDef)(duration)) {
      const key = isCenter ? 'animationDuration' : 'transitionDuration';
      style[key] = `${duration}s`;
    }

    return h('transition', {
      attrs: {
        name: transitionName,
      },
      on: {
        afterEnter: this.onOpened,
        afterLeave: this.onClosed,
      },
    }, [h('div', {
      directives: [{
        name: 'show',
        value: this.value,
      }],
      style,
      class: bem((_bem = {
        round,
      }, _bem[position] = position, _bem['safe-area-inset-bottom'] = this.safeAreaInsetBottom, _bem)),
      on: {
        click: this.onClick,
      },
    }, [this.slots(), this.closeable && h(_icon.default, {
      attrs: {
        role: 'button',
        tabindex: '0',
        name: this.closeIcon,
      },
      class: bem('close-icon', this.closeIconPosition),
      on: {
        click: this.close,
      },
    })])]);
  },
});

exports.default = _default;
